import Vue from 'vue'
import router from '../../router'
import axios from 'axios'
import {Toast} from "vant";

Vue.prototype.axiosUrl='http://course.xmythuiyi.com/Mapi.php/'

Vue.prototype.$http = {
    post: (url,params,callback) => {
        // params.token='babytesttoken1'
        params.token=localStorage.getItem('token')
        axios.post(url,params).then((res)=>{
            if(res.status===200){
                if(res.data.code==1){
                    callback(res.data.data)
                }else if(res.data.code===5) {
                    Toast('未登录，即将前往授权登录')
                    localStorage.removeItem('token')
                    setTimeout(()=>{
                        router.push({path:'/login'})
                    },1500)
                }else {
                    Toast(res.data.tips)
                }
            }else {
                Toast('系统繁忙')
            }
        })
    }
}
Vue.prototype.$wxPay = (appId,timeStamp,nonceStr,packages,signType,paySign,callBack)=>{
    WeixinJSBridge.invoke('getBrandWCPayRequest', {
            "appId":appId,
            "timeStamp": timeStamp,
            "nonceStr": nonceStr,
            "package": packages,
            "signType": signType,
            "paySign": paySign
        },
        function(res) {
            if (res.err_msg == "get_brand_wcpay_request:ok") {
                router.push({name:'Order',query:{state:0}})
                if(callBack){
                    callBack()
                }
                // 使用以上方式判断前端返回,微信团队郑重提示：
                //res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
            }
        });
}

